<?php
require_once './component/head.php';
if (!isset($_SESSION['uid'])) header('Location:./login.php');
require_once './component/drawer.php';
require_once './function/conn.php';
$info = GetInfoById($_SESSION['uid']);
$course = QueryCourse();
$notice = QueryNotice();
?>
<script type="text/javascript">
    window.onload = function () {
        CenterOnload();
    };
</script>
<div id="page-center" class="mdui-container drxs-center_page">
    <div class="mdui-row-xs-1 mdui-row-md-2">
        <div class="mdui-col" style="padding-top: 20px">
            <div class="mdui-table-fluid drxs-radius">
                <table class="mdui-table">
                    <tbody>
                    <tr>
                        <td class="drxs-td" rowspan="3">
                            <img src="./src/img/picture.jpg" alt="用户头像" width="114.4px">
                        </td>
                        <td class="drxs-td">Id: <?php echo $info['Id']; ?></td>
                        <td class="drxs-td">姓名: <?php echo $info['Name']; ?></td>
                        <td class="drxs-td">类型: <?php echo $info['Type']; ?></td>
                    </tr>
                    <tr>
                        <td colspan="3">注册日期: <?php echo $info['Date']; ?></td>
                    </tr>
                    <tr></tr>
                    </tbody>
                </table>
            </div>
        </div>
        <div class="mdui-col" style="padding-top: 20px">
            <div class="mdui-table-fluid drxs-radius">
                <table class="mdui-table mdui-table-hoverable">
                    <tbody>
                    <tr>
                        <td class="drxs-td" colspan="3">学院: <?php echo $info['College']; ?></td>
                    </tr>
                    <tr>
                        <td class="drxs-td" colspan="3">电话号码: <?php echo $info['Tel']; ?></td>
                    </tr>
                    <tr>
                        <td class="drxs-td" colspan="3">电子邮件: <?php echo $info['Email']; ?></td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <div class="mdui-row-xs-1 <?php if ($_SESSION['utype'] == '管理员') echo 'mdui-row-md-2'; else echo 'mdui-row-md-3'; ?>">
        <div class="mdui-col" style="padding-top: 20px">
            <div class="mdui-card">
                <div class="mdui-card-content">
                    <div class="mdui-row">
                        <div class="mdui-col-xs-6">系统课程</div>
                        <div id="center_more_course" class="mdui-col-xs-6 mdui-text-right">More<i
                                    class='mdui-icon material-icons'>&#xe315;</i>
                        </div>
                    </div>
                    <hr>
                    <?php
                    if (mysqli_num_rows($course) != 0) {
                        echo '<div class="mdui-list">';
                        $count = 1;
                        while ($course_info = mysqli_fetch_array($course)) :
                            if ($count > 4)
                                break;
                            ?>
                            <div class="mdui-list-item mdui-ripple">
                                <div class="mdui-list-item-content"><?php echo $course_info['CourseName']; ?></div>
                                <div class="mdui-list-item-text mdui-list-item-one-line">
                                    教师：<?php echo $course_info['TeacherName']; ?>
                                </div>
                            </div>
                            <?php
                            $count += 1;
                        endwhile;
                        echo '</div>';
                    } else
                        echo '抱歉，当前暂无课程！';
                    ?>
                </div>
            </div>
        </div>
        <?php
        if ($_SESSION['utype'] == '学生') {
            $score = QueryScore($_SESSION['uid']);
            ?>
            <div class='mdui-col' style='padding-top: 20px'>
                <div class='mdui-card'>
                    <div class='mdui-card-content'>
                        <div class='mdui-row'>
                            <div class='mdui-col-xs-6'>最新成绩</div>
                            <div id='center_more_score' class='mdui-col-xs-6 mdui-text-right'>More<i
                                        class='mdui-icon material-icons'>&#xe315;</i></div>
                        </div>
                        <hr>
                        <?php
                        if (mysqli_num_rows($score) != 0) {
                            echo '<div class="mdui-list">';
                            $count = 1;
                            while ($score_info = mysqli_fetch_array($score)) :
                                if ($count > 4)
                                    break;
                                ?>
                                <div class="mdui-list-item mdui-ripple">
                                    <div class="mdui-list-item-content"><?php echo $score_info['CourseName']; ?></div>
                                    <div class="mdui-list-item-text mdui-list-item-one-line"><?php echo $score_info['Score']; ?>
                                        分
                                    </div>
                                </div>
                                <?php
                                $count += 1;
                            endwhile;
                            echo '</div>';
                        } else
                            echo '抱歉，当前暂无成绩！';
                        ?>
                    </div>
                </div>
            </div>
        <?php }
        if ($_SESSION['utype'] == '教师') {
            $teaching = QueryTeachingCourse($_SESSION['uid']); ?>
            <div class='mdui-col' style='padding-top: 20px'>
                <div class='mdui-card'>
                    <div class='mdui-card-content'>
                        <div class='mdui-row'>
                            <div class='mdui-col-xs-6'>讲授课程</div>
                            <div id='center_more_teaching' class='mdui-col-xs-6 mdui-text-right'>More<i
                                        class='mdui-icon material-icons'>&#xe315;</i></div>
                        </div>
                        <hr>
                        <?php
                        if (mysqli_num_rows($teaching) != 0) {
                            echo '<div class="mdui-list">';
                            $count = 1;
                            while ($teaching_info = mysqli_fetch_array($teaching)) :
                                if ($count > 4)
                                    break;
                                ?>
                                <div class="mdui-list-item mdui-ripple">
                                    <div class="mdui-list-item-content">{$teaching_info['CourseName']}</div>
                                    <div class="mdui-list-item-text mdui-list-item-one-line">{$teaching_info['Time']}
                                    </div>
                                </div>
                                <?php $count += 1;
                            endwhile;
                            echo '</div>';
                        } else
                            echo '抱歉，当前暂无数据！';
                        ?>
                    </div>
                </div>
            </div>
        <?php } ?>
        <div class="mdui-col" style="padding-top: 20px">
            <div class="mdui-card">
                <div class="mdui-card-content">
                    <div class="mdui-row">
                        <div class="mdui-col-xs-6">最新公告</div>
                        <div id="center_more_notice" class="mdui-col-xs-6 mdui-text-right">More<i
                                    class='mdui-icon material-icons'>&#xe315;</i>
                        </div>
                    </div>
                    <hr>
                    <?php
                    if (mysqli_num_rows($notice) != 0) {
                        echo '<div class="mdui-list">';
                        $count = 1;
                        while ($notice_info = mysqli_fetch_array($notice)) :
                            if ($count > 4)
                                break;
                            $publisher_name = GetInfoById($notice_info['PublisherId'])['Name'];
                            if (strlen($notice_info['NoticeTitle']) > 27) $title = substr($notice_info['NoticeTitle'], 0, 27) . '...';
                            else $title = $notice_info['NoticeTitle'];
                            ?>
                            <div class="mdui-list-item mdui-ripple">
                                <div class="mdui-list-item-content"><?php echo $title; ?></div>
                                <div class="mdui-list-item-text mdui-list-item-one-line">
                                    发布人：<?php echo $publisher_name; ?></div>
                            </div>
                            <?php
                            $count += 1;
                        endwhile;
                        echo '</div>';
                    } else
                        echo '抱歉，当前暂无公告！';
                    ?>
                </div>
            </div>
        </div>
    </div>
</div>

<?php require_once './component/footer.php'; ?>
